package com.ff.xyh.consumer.dictionary.controller;


import com.ff.xyh.common.entity.dictionary.ComplaintStatus;
import com.ff.xyh.common.entity.dictionary.ComplaintType;
import com.ff.xyh.common.entity.result.ResultMessage;
import com.ff.xyh.common.entity.result.ResultObject;
import com.ff.xyh.consumer.dictionary.service.ComplaintStatusService;
import com.ff.xyh.consumer.dictionary.service.ComplaintTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 投诉状态表 前端控制器
 * </p>
 *
 * @author ff
 * @since 2022-10-26
 */
@Api(tags = "举报相关接口")
@RestController
@RequestMapping("/dictionary")
public class ComplaintStatusController {

    @Autowired
    private ComplaintStatusService complaintStatusService;

    @ApiOperation(value = "获取所有举报状态信息")
    @GetMapping("get-complaint-status-all")
    public ResultObject getAllComplaintStatus() {
        List<ComplaintStatus> list = complaintStatusService.list(null);
        if (list == null || list.isEmpty()){
            return ResultObject.error().message(ResultMessage.NO_RESULT);
        } else {
            Map map = new HashMap();
            map.put("items", list);
            return ResultObject.ok().data(map);
        }
    }

    @ApiOperation(value = "根据id获取举报状态信息")
    @GetMapping("get-complaint-status-id")
    public ResultObject getComplaintStatusById(
            @RequestParam(name = "id") Integer id) {
        ComplaintStatus complaintStatus = complaintStatusService.getById(id);
        if (complaintStatus == null){
            return ResultObject.error().message(ResultMessage.NO_RESULT);
        } else {
            Map map = new HashMap();
            map.put("data", complaintStatus);
            return ResultObject.ok().data(map);
        }
    }

    @ApiOperation(value = "根据id删除举报状态信息")
    @GetMapping("delete-complaint-status-id")
    public ResultObject deleteComplaintStatusById(
            @RequestParam(name = "id") Integer id) {
        ComplaintStatus complaintStatus = complaintStatusService.getById(id);
        if (complaintStatus == null){
            return ResultObject.error().message(ResultMessage.NO_SUCH_OBJECT);
        } else {
            if (complaintStatusService.removeById(id)) {
                Map map = new HashMap();
                map.put("data", complaintStatus);
                return ResultObject.ok().data(map);
            } else {
                return ResultObject.error().message(ResultMessage.OBJECT_EXISTS_BUT_FAILED_TO_DELETE);
            }
        }
    }

    @ApiOperation(value = "添加举报状态信息")
    @PostMapping("insert-complaint-status")
    public ResultObject insertComplaintStatus (
            @RequestBody ComplaintStatus complaintStatus) {
        if (complaintStatusService.getById(complaintStatus.getId()) != null){
            return ResultObject.error().message(ResultMessage.OBJECT_ALREADY_EXISTS);
        } else {
            if (complaintStatusService.save(complaintStatus)) {
                Map map = new HashMap();
                map.put("data", complaintStatus);
                return ResultObject.ok().data(map);
            } else {
                return ResultObject.error().message(ResultMessage.NO_SUCH_OBJECT_BUT_FAILED_TO_INSERT);
            }
        }
    }

    @ApiOperation(value = "修改举报状态信息")
    @PostMapping("update-complaint-status")
    public ResultObject updateComplaintStatus(
            @RequestBody ComplaintStatus complaintStatus) {
        if (complaintStatusService.getById(complaintStatus.getId()) == null){
            return ResultObject.error().message(ResultMessage.NO_SUCH_OBJECT);
        } else {
            if (complaintStatusService.updateById(complaintStatus)) {
                Map map = new HashMap();
                map.put("data", complaintStatus);
                return ResultObject.ok().data(map);
            } else {
                return ResultObject.error().message(ResultMessage.OBJECT_EXISTS_BUT_FAILED_TO_UPDATE);
            }
        }
    }

}

